//
//  PlayVC.m
//  Faker
//
//  Created by dllo on 15/10/28.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZGLPlayVC.h"
#import "ZGLHTTPTOOL.h"
#import "ZGLPlayFirstView.h"
#import <UIImageView+AFNetworking.h>
#import <SDWebImage/UIButton+WebCache.h>
#import "ZGLPlayFirstModel.h"
#import "ZGLFirstMainModel.h"
#import "ZGLPlayHomeFirstTVC.h"
#import "ZGLPlayHomeSecondTVC.h"
#import "ZGLPlayDetailModel.h"
#import "ZGLPlayClassModel.h"
#import "ZGLPlayButtonVC.h"
#import "ZGLPlayWeeklyVC.h"
#import "ZGLPlayDetailWebVC.h"
#import "ZGLPlayMainVC.h"
#import "ZGLPlayLocationVC.h"
#import "ZGLPlayEditVC.h"
#import "ZGLmyVC.h"



#pragma mark 1 - 声明属性 签协议
@interface ZGLPlayVC ()<UITableViewDataSource, UITableViewDelegate, ZGLPlayLocationVCDelegate>
@property (nonatomic, strong) UITableView *tableView;
/* 用来装顶部的点击Model */
@property (nonatomic, strong) NSMutableArray *modelArr;
/* 设置显示button的view为属性  */
@property (nonatomic, strong) UIView *headView;
/* 用来装主显示部分的model */
@property (nonatomic, strong) NSMutableArray *mainModelArr;
/* 用来装传值的model */
@property (nonatomic, strong) NSMutableArray *nextModelArr;
/* 用来装特殊的热门城市 */
@property (nonatomic, strong) NSArray *cityArr;
/* 将定位bar设置为属性 */
@property (nonatomic, strong) UIBarButtonItem *barButtonItem;
/* 将ZGLPlayLocationVC设置为属性 方便设置代理人 */
@property (nonatomic, strong) ZGLPlayLocationVC *locationVC;
@property (nonatomic, strong) UIActivityIndicatorView *activityIndicatorView;


@end

@implementation ZGLPlayVC


/* 内存管理 */
-(void)dealloc {
    self.tableView.delegate = nil;
    self.tableView.dataSource = nil;
    self.locationVC.delegate = nil;
    
}
/* 视图将要出现时 改变导航栏颜色*/
-(void)viewWillAppear:(BOOL)animated {
     [super viewWillAppear:animated];
    [self.headView reloadInputViews];
    self.tableView.backgroundColor = backColor;
    self.view.backgroundColor = backColor;
    self.headView.backgroundColor = foreColor;
    [self.tableView reloadData];
    [self.view reloadInputViews];
    /* 调用pch文件中的单例 */
    self.navigationController.navigationBar.barTintColor = naviColor;
   
    
}

#pragma mark 2 - 主程序入口
- (void)viewDidLoad {
    [super viewDidLoad];
    
    /* 初始化ZGLPlayLocationVC对象 */
    _locationVC = [[ZGLPlayLocationVC alloc] init];
    /* 设置代理人 */
     _locationVC.delegate = self;
    /* 特殊的热门城市 */
    self.cityArr = @[@"北京", @"上海", @"广州", @"深圳", @"成都", @"重庆", @"杭州", @"武汉", @"南京", @"天津"];
    /* 创建creatTavleView */
    [self creatTableView];
    /* 创建导航栏 */
    [self designNavigationBar];
    self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 60 * ScaleX, 40 * ScaleX)];
    self.activityIndicatorView.center = self.view.center;
    [self.view addSubview:self.activityIndicatorView];
    self.activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    [self.activityIndicatorView startAnimating];
    // Do any additional setup after loading the view.
}
#pragma mark 3 - tableView部分
/* 创建部分 */
-(void)creatTableView {
    /* 初始化对象 */
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Width, Height + 50 * ScaleX) style:UITableViewStyleGrouped];
    [self.view addSubview:self.tableView];
    /* 设置代理人 */
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    /* 注册cell */
    [self.tableView registerClass:[ZGLPlayHomeFirstTVC class] forCellReuseIdentifier:@"ZGLPlayHomeFirstTVC"];
    [self.tableView registerClass:[ZGLPlayHomeSecondTVC class] forCellReuseIdentifier:@"ZGLPlayHomeSecondTVC"];

}
/* 行数 */
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    ZGLFirstMainModel *model = [self.mainModelArr objectAtIndex:section];
    /* 多加一行用于显示标题 点击标题会有跳转 */
    return model.items.count + 1;
}
/* 分区数 */
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.mainModelArr.count;
}
/* cell赋值部分 */
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    /* 从数组中取出model */
    ZGLFirstMainModel *model = [self.mainModelArr objectAtIndex:indexPath.section];
    /* 好玩周报 有礼派赋值 */
    if ([model.title isEqualToString:@"好玩周报"] || [model.title isEqualToString:@"有礼派"])
    {
        ZGLPlayHomeFirstTVC *cell = [tableView dequeueReusableCellWithIdentifier:@"ZGLPlayHomeFirstTVC"];
        /* 第一行赋值和其他行不一样 */
        if (0 == indexPath.row) {
            [cell.titleImage setImageWithURL:[NSURL URLWithString:model.banner[@"url"]] placeholderImage:[UIImage imageNamed:@"place1.jpg"]];
        }else {
            [cell.titleImage setImageWithURL:model.items[indexPath.row - 1][@"pic"][@"url"] placeholderImage:[UIImage imageNamed:@"place1.jpg"]];
        }
        return cell;
        
    }
    /* 其他部分赋值 */
    else {
        /* 第一行赋值 */
        if (0 == indexPath.row) {
            ZGLPlayHomeFirstTVC *cell = [tableView dequeueReusableCellWithIdentifier:@"ZGLPlayHomeFirstTVC"];
            [cell.titleImage setImageWithURL:[NSURL URLWithString:model.banner[@"url"]] placeholderImage:[UIImage imageNamed:@"place1.jpg"]];
            return cell;
        }
        else {
            ZGLPlayHomeSecondTVC *cell = [tableView dequeueReusableCellWithIdentifier:@"ZGLPlayHomeSecondTVC"];
            [cell.mainImage setImageWithURL:[NSURL URLWithString:model.items[indexPath.row - 1][@"pic"][@"url"]] placeholderImage:[UIImage imageNamed:@"place1.jpg"]];
            cell.titleLabel.text = model.items[indexPath.row - 1][@"title"];
            cell.contentLabel.text = model.items[indexPath.row - 1][@"content"];
            return cell;
        }
    }
}
/* 行高 */
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZGLFirstMainModel *model = [self.mainModelArr objectAtIndex:indexPath.section];
    /* 好玩周报 有礼派*/
    if ([model.title isEqualToString:@"好玩周报"] || [model.title isEqualToString:@"有礼派"]) {
        if (0 == indexPath.row) {
            return 100 *ScaleX;
        }else {
            return 200 * ScaleX;
        }
    }
    /* 其余部分 */
    else {
        if (0 == indexPath.row) {
            return 100 * ScaleX;
        }else {
            return 250 * ScaleX;
        }
    }
}
/* Header高度设置 */
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (0 == section) {
        return CGFLOAT_MIN;
    }else {
        return 5;
    }
}
#pragma mark 4 - 设计NavigationBar
-(void)designNavigationBar {
    /* 左边标题设置 */
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] init];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem.title = @"玩乐";
    /* 右边两个item设计 */
    //定位bar
    self.barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"大连" style:UIBarButtonItemStyleDone target:self action:@selector(location)];
    self.barButtonItem.tintColor = [UIColor whiteColor];
    //个人中心
    UIBarButtonItem *personBar = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"lianxiren"]  style:UIBarButtonItemStyleDone target:self action:@selector(personBar)];
    personBar.tintColor = [UIColor whiteColor];
    //调用定位方法
    [self asynGETJSONWithURL:@"http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" completion:^(id result) {
        self.barButtonItem.title = result[@"city"];
        //将参数传给tableView显示部分进行数据处理
        [self handleMainDataWithLocationCity:result[@"city"]];
    }];
    self.navigationItem.rightBarButtonItems = @[personBar, self.barButtonItem];
}
#pragma mark 4 ** 右边两个bar点击事件
//个人中心
-(void)personBar {
    ZGLmyVC *myVC = [[ZGLmyVC alloc] init];
    [self.navigationController pushViewController:myVC animated:YES];
}
//定位城市
-(void)location {
    _locationVC.modelArr = self.modelArr;
    /* 将城市名传值 */
    _locationVC.city = self.barButtonItem.title;
    [self.navigationController pushViewController:_locationVC animated:YES];
}
#pragma mark 4 ** ZGLPlayLocationVC代理方法实现
-(void)passCityName:(NSString *)cityName {
    //将参数赋给定位bar
    self.barButtonItem.title = cityName;
    //判断是否为特殊热门城市
    if ([self.cityArr containsObject:cityName]) {
        /* 移除视图 */
        [self.headView removeFromSuperview];
        /* 改变tableView布局 */
        self.tableView.frame = CGRectMake(0, 100 * ScaleX, Width, Height - 50 * ScaleX);
        [self handleDataWithCurrentCity:cityName];
    }
    else {
        //将顶部button视图移除
        for (UIView *view in self.headView.subviews) {
            if ([view isKindOfClass:[ZGLPlayFirstView class]]) {
                [view removeFromSuperview];
            }
        }
        [self.headView removeFromSuperview];
        self.tableView.frame = CGRectMake(0, 0, Width, Height);
        [self.view reloadInputViews];
    }
    //换定位城市的时候 重新数据处理
    NSMutableString *urlStr = [NSMutableString stringWithString: @"http://wl.myzaker.com/?_appid=AndroidPhone&_v=6.4.1&_version=6.41&c=columns&city="];
    [urlStr appendString:cityName];
    NSString *striEncoding = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [ZGLHTTPTOOL GETWithURL:striEncoding withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        self.mainModelArr = [NSMutableArray arrayWithCapacity:0];
        NSDictionary *dic = [result objectForKey:@"data"];
        NSArray *arr = [dic objectForKey:@"columns"];
        for (NSDictionary *dic in arr) {
            ZGLFirstMainModel *model = [ZGLFirstMainModel modWithDic:dic];
            [self.mainModelArr addObject:model];
        }
        [self.tableView reloadData];
    } withFail:^(id result) {
        
    }];
    [self.view reloadInputViews];
}
#pragma mark 4 ** 定位方法实现
- (void)asynGETJSONWithURL:(NSString *)urlString completion:(void(^)(id result))block {
    /* 1.转码 */
    NSString *enCodingStr = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    /* 2.创建URL对象 */
    NSURL *url = [NSURL URLWithString:enCodingStr];
    /* 3.创建请求 */
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    /* 4.创建链接接受数据 */
    NSURLSessionTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

        /* 5.数据解析 */

        NSString *temResult = [[NSString alloc] initWithData:data  encoding:NSUTF8StringEncoding];
        if (temResult.length == 0) {
            return ;
        }
        temResult = [temResult substringFromIndex:21];
        temResult = [temResult substringToIndex:temResult.length - 1];
        NSData* xmlData = [temResult dataUsingEncoding:NSUTF8StringEncoding];
        id result = [NSJSONSerialization JSONObjectWithData:xmlData options:NSJSONReadingMutableContainers error:&error];
        /* 6.通过block将result值返回出去 */
        block(result);
    }];
    [task resume];
}
#pragma mark 5 - 顶部button数据处理
-(void)handleDataWithCurrentCity:(NSString *)city {
    NSMutableString *urlStr = [NSMutableString stringWithString: @"http://wl.myzaker.com/?_appid=AndroidPhone&_v=6.4.1&_version=6.41&c=category_list&city="];
    [urlStr appendString:city];
    NSString *striEncoding = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [ZGLHTTPTOOL GETWithURL:striEncoding withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
        self.modelArr = [NSMutableArray arrayWithCapacity:0];
        NSDictionary *dic = [result objectForKey:@"data"];
        NSArray *arr = [dic objectForKey:@"list"];
        for (NSDictionary *dic in arr) {
            ZGLPlayFirstModel *model = [ZGLPlayFirstModel modWithDic:dic];
            [array addObject:model];
        }
        self.modelArr = array;
        [self creatButtonViewWithCurrentCity:city];
        [self.tableView reloadData];
    } withFail:^(id result) {
        
    }];
    
    
}
#pragma mark 6 - 主界面部分数据处理
-(void)handleMainDataWithLocationCity:(NSString *)city {
    /* url拼接以及汉字转码 */
    NSMutableString *urlStr = [NSMutableString stringWithString: @"http://wl.myzaker.com/?_appid=AndroidPhone&_v=6.4.1&_version=6.41&c=columns&city="];
    [urlStr appendString:city];
    NSString *striEncoding = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    /* 数据处理 */
    [ZGLHTTPTOOL GETWithURL:striEncoding withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        self.mainModelArr = [NSMutableArray arrayWithCapacity:0];
        NSDictionary *dic = [result objectForKey:@"data"];
        NSArray *arr = [dic objectForKey:@"columns"];
        for (NSDictionary *dic in arr) {
            ZGLFirstMainModel *model = [ZGLFirstMainModel modWithDic:dic];
            [self.mainModelArr addObject:model];
        }
        [self.tableView reloadData];
        [self.activityIndicatorView stopAnimating];
    } withFail:^(id result) {
        
    }];
}
#pragma mark 7 - 顶部button视图创建
-(void)creatButtonViewWithCurrentCity:(NSString *)city {
    [self.tableView reloadData];
    /* 创建对象 */
    self.headView = [[UIView alloc] init];
    self.headView.backgroundColor = foreColor;
    [self.headView setFrame:CGRectMake(0, 64, self.tableView.frame.size.width , 100 * ScaleX)];
    /* 铺button */
        for (int i = 0; i < 5; i++) {
            ZGLPlayFirstModel *model = [self.modelArr objectAtIndex:i + 1];
            ZGLPlayFirstView *view = [[ZGLPlayFirstView alloc] initWithFrame:CGRectMake(0 + i * 75 * ScaleX, 0, 75 * ScaleX, self.headView.frame.size.height - 10 * ScaleX)];
            [self.headView addSubview:view];
            view.button.titleLabel.text = city;
            [view.button sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", model.icon]] forState:UIControlStateNormal];
            view.tag = 2000 + i;
            [view.button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
            view.button.tag = i + 1;
            view.label.text = [NSString stringWithFormat:@"%@", model.category];
        }
    [self.view addSubview:self.headView];
}
#pragma mark 8 - button 点击事件
-(void)button:(UIButton *)button {
    /* 创建对象 */
    ZGLPlayButtonVC *buttonVC = [[ZGLPlayButtonVC alloc] init];
    if (button.tag == 1) {
        NSMutableString *urlStr = [NSMutableString stringWithString: @"http://wl.myzaker.com/?_appid=AndroidPhone&_v=6.4.1&_version=6.41&c=activity_list&category=1&city="];
        [urlStr appendString:button.titleLabel.text];
        NSString *striEncoding = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        [ZGLHTTPTOOL GETWithURL:striEncoding withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
            self.nextModelArr = [NSMutableArray arrayWithCapacity:0];
            NSDictionary *dic = [result objectForKey:@"data"];
            NSArray *arr = [dic objectForKey:@"weekends"];
            for (NSDictionary *dic in arr) {
                ZGLPlayDetailModel *model = [ZGLPlayDetailModel modWithDic:dic];
                [self.nextModelArr addObject:model];
                buttonVC.modelArr = self.nextModelArr;
            }
        } withFail:^(id result) {
            
        }];
    }
    else if (button.tag == 2) {
        NSMutableString *urlStr = [NSMutableString stringWithString: @"http://wl.myzaker.com/?_appid=AndroidPhone&_v=6.4.1&_version=6.41&c=activity_list&category=4&city="];
        [urlStr appendString:button.titleLabel.text];
        NSString *striEncoding = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        [ZGLHTTPTOOL GETWithURL:striEncoding withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
            self.nextModelArr = [NSMutableArray arrayWithCapacity:0];
            NSDictionary *dic = [result objectForKey:@"data"];
            NSArray *arr = [dic objectForKey:@"weekends"];
            for (NSDictionary *dic in arr) {
                ZGLPlayDetailModel *model = [ZGLPlayDetailModel modWithDic:dic];
                [self.nextModelArr addObject:model];
                buttonVC.modelArr = self.nextModelArr;
            }
        } withFail:^(id result) {
            
        }];
    }
    else if (button.tag == 3) {
        NSMutableString *urlStr = [NSMutableString stringWithString: @"http://wl.myzaker.com/?_appid=AndroidPhone&_v=6.4.1&_version=6.41&c=movie_list&city="];
        [urlStr appendString:button.titleLabel.text];
        NSString *striEncoding = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        [ZGLHTTPTOOL GETWithURL:striEncoding withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
            self.nextModelArr = [NSMutableArray arrayWithCapacity:0];
            NSDictionary *dic = [result objectForKey:@"data"];
            NSArray *arr = [dic objectForKey:@"weekends"];
            for (NSDictionary *dic in arr) {
                ZGLPlayDetailModel *model = [ZGLPlayDetailModel modWithDic:dic];
                [self.nextModelArr addObject:model];
                buttonVC.modelArr = self.nextModelArr;
            }
        } withFail:^(id result) {
            
        }];
    }
    else if(button.tag == 4) {
        NSMutableString *urlStr = [NSMutableString stringWithString: @"http://wl.myzaker.com/?_appid=AndroidPhone&_v=6.4.1&_version=6.41&c=activity_list&category=9&city="];
        [urlStr appendString:button.titleLabel.text];
        [urlStr appendString:@"&p=0&size=20"];
        NSString *striEncoding = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        [ZGLHTTPTOOL GETWithURL:striEncoding withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
            self.nextModelArr = [NSMutableArray arrayWithCapacity:0];
            NSDictionary *dic = [result objectForKey:@"data"];
            NSArray *arr = [dic objectForKey:@"weekends"];
            for (NSDictionary *dic in arr) {
                ZGLPlayDetailModel *model = [ZGLPlayDetailModel modWithDic:dic];
                [self.nextModelArr addObject:model];
                buttonVC.modelArr = self.nextModelArr;
            }
        } withFail:^(id result) {
            
        }];
        
    }else {
        NSMutableString *urlStr = [NSMutableString stringWithString: @"http://wl.myzaker.com/?_appid=AndroidPhone&_v=6.4.1&_version=6.41&c=activity_list&category=3&city="];
        [urlStr appendString:button.titleLabel.text];
        [urlStr appendString:@"&p=0&size=20"];
        NSString *striEncoding = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        [ZGLHTTPTOOL GETWithURL:striEncoding withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
            self.nextModelArr = [NSMutableArray arrayWithCapacity:0];
            NSDictionary *dic = [result objectForKey:@"data"];
            NSArray *arr = [dic objectForKey:@"weekends"];
            for (NSDictionary *dic in arr) {
                ZGLPlayDetailModel *model = [ZGLPlayDetailModel modWithDic:dic];
                [self.nextModelArr addObject:model];
                buttonVC.modelArr = self.nextModelArr;
            }
        } withFail:^(id result) {
            
        }];
       
    }
     [self.navigationController pushViewController:buttonVC animated:YES];
}
#pragma mark 9 - cell点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    /* 取出model */
    ZGLFirstMainModel *model = [self.mainModelArr objectAtIndex:indexPath.section];
    /* 有礼派 */
    if ([model.title isEqualToString:@"有礼派"]) {
        /* 创建对象 */
        ZGLPlayWeeklyVC *weeklyVC = [[ZGLPlayWeeklyVC alloc] init];
        ZGLPlayDetailWebVC *webVC = [[ZGLPlayDetailWebVC alloc] init];
        /* 如果为第一行 点击进入全部详情 */
        if (0 == indexPath.row)
        {
        /* 有礼派自己没有数据 取第一个model的数据 如果有礼派为第一个model 区第三个的 */
            ZGLFirstMainModel *model1 = [self.mainModelArr objectAtIndex:0];
            if ([model1.title isEqualToString:@"有礼派"]) {
                model1 = [self.mainModelArr objectAtIndex:2];
            }
            [ZGLHTTPTOOL GETWithURL:model1.more_info[@"api_url"] withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result)
             {
                 self.nextModelArr = [NSMutableArray arrayWithCapacity:0];
                 NSDictionary *dic = [result objectForKey:@"data"];
                 NSArray *arr = [dic objectForKey:@"items"];
                 for (NSDictionary *dic in arr)
                 {
                     ZGLPlayClassModel *model = [ZGLPlayClassModel modWithDic:dic];
                     [self.nextModelArr addObject:model];
                     weeklyVC.modelArr = self.nextModelArr;
                 }
             }
                           withFail:^(id result) {}];
           [self.navigationController pushViewController:weeklyVC animated:YES];
        }
        /* 否则推出单个网页详情 */
        else {
            webVC.webStr = model.items[indexPath.row - 1][@"web"][@"url"];
            [self.navigationController pushViewController:webVC animated:YES];
        }

        
    }
    /* 逼格一刻 编辑之选 */
    else if ([model.title isEqualToString:@"逼格一刻"] || [model.title isEqualToString:@"编辑之选"]) {
        ZGLPlayMainVC *mainVC = [[ZGLPlayMainVC alloc] init];
        ZGLPlayDetailWebVC *webVC = [[ZGLPlayDetailWebVC alloc] init];
        if (0 == indexPath.row) {
            [ZGLHTTPTOOL GETWithURL:model.more_info[@"api_url"] withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
                self.nextModelArr = [NSMutableArray arrayWithCapacity:0];
                NSDictionary *dic = [result objectForKey:@"data"];
                NSArray *arr = [dic objectForKey:@"items"];
                for (NSDictionary *dic in arr) {                  
                    ZGLPlayClassModel *model = [ZGLPlayClassModel modWithDic:dic];
                    [self.nextModelArr addObject:model];
                    mainVC.modelArr = self.nextModelArr;
                }
            }
                           withFail:^(id result) {}];
            [self.navigationController pushViewController:mainVC animated:YES];
        }
        else {
            webVC.webStr = model.items[indexPath.row - 1][@"article"][@"weburl"];
            [self.navigationController pushViewController:webVC animated:YES];
        }

        
    }
    /* 好玩周报 */
    else if([model.title isEqualToString:@"好玩周报"]) {
        
        ZGLPlayWeeklyVC *weeklyVC = [[ZGLPlayWeeklyVC alloc] init];
        ZGLPlayDetailWebVC *webVC = [[ZGLPlayDetailWebVC alloc] init];
        if (0 == indexPath.row)
        {
            [ZGLHTTPTOOL GETWithURL:model.more_info[@"api_url"] withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result)
             {
                 self.nextModelArr = [NSMutableArray arrayWithCapacity:0];
                 NSDictionary *dic = [result objectForKey:@"data"];
                 NSArray *arr = [dic objectForKey:@"items"];
                 for (NSDictionary *dic in arr)
                 {
                ZGLPlayClassModel *model = [ZGLPlayClassModel modWithDic:dic];
                [self.nextModelArr addObject:model];
                weeklyVC.modelArr = self.nextModelArr;
                 }
             }
                           withFail:^(id result) {}];
            [self.navigationController pushViewController:weeklyVC animated:YES];
        }
        else {
            webVC.webStr = model.items[indexPath.row - 1][@"article"][@"weburl"];
            [self.navigationController pushViewController:webVC animated:YES];
        }
 
    }
    /* 其余部分 */
    else {
        ZGLPlayEditVC *editVC = [[ZGLPlayEditVC alloc] init];
        ZGLPlayDetailWebVC *webVC = [[ZGLPlayDetailWebVC alloc] init];
        if (0 == indexPath.row) {
        [ZGLHTTPTOOL GETWithURL:model.more_info[@"api_url"] withBody:nil withHttpHead:nil responseStyle:JSON withSuccess:^(id result) {
        self.nextModelArr = [NSMutableArray arrayWithCapacity:0];
        NSDictionary *dic = [result objectForKey:@"data"];
        NSArray *arr = [dic objectForKey:@"weekends"];
        for (NSDictionary *dic in arr) {
            ZGLPlayDetailModel *model = [ZGLPlayDetailModel modWithDic:dic];
            [self.nextModelArr addObject:model];
            editVC.modelArr = self.nextModelArr;
                }
            }
            withFail:^(id result) {}];
        [self.navigationController pushViewController:editVC animated:YES];
        }
        else {
            webVC.webStr = model.items[indexPath.row - 1][@"weekend"][@"content_url"];
            [self.navigationController pushViewController:webVC animated:YES];
        }
 
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
